clear all

foreach data in $datafilesfirm {

	* Set globals:
		global dataspec `data'
		global n = 2
		global rhs1 diff_ln_IND 
		global rhs2 diff_wIPT_IND_CHN
		global ivs1 diff_ln_IVS 
		global ivs2 diff_wIPT_LMI_CHN_EXCL_IND
		global ctrl 
	do "$code/estimation/flexible/firm_regs.do"

	* Set globals:
		global dataspec `data'
		global n = 3
		global rhs1 diff_ln_IND 
		global rhs2 
		global ivs1 diff_ln_IVS 
		global ivs2 
		global ctrl diff_wIPT_LMI_CHN_EXCL_IND
	do "$code/estimation/flexible/firm_regs.do"

	use "$tempfold/bs2_`data'", clear
	merge 1:1 bs using "$tempfold/bs3_`data'", nogen
	save "$BS_fold/bs_`data'", replace

}

foreach data in $datafiles {

	* Set globals:
		global dataspec `data'
		global n = 2
		global rhs1 diff_ln_IND 
		global rhs2 diff_wIPT_IND_CHN
		global ivs1 diff_ln_IVS 
		global ivs2 diff_wIPT_LMI_CHN_EXCL_IND
		global ctrl 
	do "$code/estimation/flexible/decomp_regs_mp.do"

	* Set globals:
		global dataspec `data'
		global n = 3
		global rhs1 diff_ln_IND 
		global rhs2 
		global ivs1 diff_ln_IVS 
		global ivs2 
		global ctrl diff_wIPT_LMI_CHN_EXCL_IND
	do "$code/estimation/flexible/decomp_regs_mp.do"

	use "$tempfold/bs2_`data'", clear
	merge 1:1 bs using "$tempfold/bs3_`data'", nogen
	save "$BS_fold/bs_`data'_mp", replace

}

foreach data in $datafiles {

	* Set globals:
		global dataspec `data'
		global n = 2
		global rhs1 diff_ln_IND 
		global rhs2 diff_wIPT_IND_CHN
		global ivs1 diff_ln_IVS 
		global ivs2 diff_wIPT_LMI_CHN_EXCL_IND
		global ctrl 
	do "$code/estimation/flexible/decomp_regs.do"

	* Set globals:
		global dataspec `data'
		global n = 3
		global rhs1 diff_ln_IND 
		global rhs2 
		global ivs1 diff_ln_IVS 
		global ivs2 
		global ctrl diff_wIPT_LMI_CHN_EXCL_IND
	do "$code/estimation/flexible/decomp_regs.do"

	use "$tempfold/bs2_`data'", clear
	merge 1:1 bs using "$tempfold/bs3_`data'", nogen
	save "$BS_fold/bs_`data'", replace

	
	***************** Interacted By Size *****************

	* Set globals:
		global dataspec `data'
		global n = 2
		global rhs1 c.diff_ln_IND#size
		global rhs2 c.diff_wIPT_IND_CHN#size
		global ivs1 c.diff_ln_IVS#size
		global ivs2 c.diff_wIPT_LMI_CHN_EXCL_IND#size
		global ctrl 
	do "$code/estimation/flexible/decomp_regs_interactions.do"

	* Set globals:
		global dataspec `data'
		global n = 3
		global rhs1 c.diff_ln_IND#size
		global rhs2 
		global ivs1 c.diff_ln_IVS#size
		global ivs2 
		global ctrl c.diff_wIPT_LMI_CHN_EXCL_IND#size
	do "$code/estimation/flexible/decomp_regs_interactions.do"

	use "$tempfold/bs2_`data'", clear
	merge 1:1 bs using "$tempfold/bs3_`data'", nogen
	save "$BS_fold/bsi_`data'", replace
	
	
		***************** Interacted By Size (salaries) *****************

	* Set globals:
		global dataspec `data'
		global n = 2
		global rhs1 c.diff_ln_IND#size
		global rhs2 c.diff_wIPT_IND_CHN#size
		global ivs1 c.diff_ln_IVS#size
		global ivs2 c.diff_wIPT_LMI_CHN_EXCL_IND#size
		global ctrl 
	do "$code/estimation/flexible/decomp_regs_interactions_salaries.do"

	* Set globals:
		global dataspec `data'
		global n = 3
		global rhs1 c.diff_ln_IND#size
		global rhs2 
		global ivs1 c.diff_ln_IVS#size
		global ivs2 
		global ctrl c.diff_wIPT_LMI_CHN_EXCL_IND#size
	do "$code/estimation/flexible/decomp_regs_interactions_salaries.do"

	use "$tempfold/bs2_`data'", clear
	merge 1:1 bs using "$tempfold/bs3_`data'", nogen
	save "$BS_fold/bsiwage_`data'", replace
}

